// require('./../style/animation.scss');

var divMask = '';
var timer = null;
var Alert = function(text, duration) {
  var durations = duration || 3000;
  function close() {
    if (typeof ReactDom === 'object') {
      ReactDom.unmountComponentAtNode(divMask);
    }
    if (divMask && divMask.parentNode) {
      divMask.parentNode.removeChild(divMask);
    }
    divMask = '';
  }
  if (divMask) {
    close();
    clearTimeout(timer);
    timer = null;
  }
  var template = '<div>' + text + '</div>';
  divMask = document.createElement('div');
  divMask.innerHTML = template;
  divMask.classList.add('c-login-alert');
  document.body.appendChild(divMask);
  require('./../style/animation.scss');
  require('./../style/alert.scss');
  timer = setTimeout(() => {
    close();
  }, durations);
};

module.exports = Alert;
